from time import time

def bsv1(A):
         for j in range(len(A) - 1, - 1, - 1):
                  for i in range(j):
                           if A[i] > A[i+1]:
                                    D=A[i]
                                    A[i] = A[i+1]
                                    A[i+1]=D

def bsv2(A):
         aiss=False
         N=len(A)-1
         while N>0 and not aiss:
                  aiss=True
                  for i in range(N):
                           if A[i] > A[i+1]:
                                    D=A[i]
                                    A[i] = A[i+1]
                                    A[i+1]=D
                                    aiss=False
                  N-=1

def ctime(ar, sf):
    bt=time()
    sf(ar)
    et=time()
    return int((et-bt)*1000)

for fname in ("m1_sorted.txt", "m2_reverse.txt", "m3_shuffle.txt"):
         f = open(fname, "r")
         data=[int(x) for x in f]
         f.close()
         data2=data.copy()
         st1=ctime(data, bsv1)
         st2=ctime(data2, bsv2)
         print(fname, "Отсортерованно за", st1, "пузырьковой сортировкой 1")
         print(fname, "Отсортерованно за", st2, "пузырьковой сортировкой 2")
                  
